package com.zzyl.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.pojo.NursingProject;
import com.zzyl.pojo.PageResult;
import com.zzyl.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class NursingProjectController {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    @GetMapping("/customer/orders/project/page")
    public Result<PageResult<NursingProject>> findByPage(Integer userId, Integer pageNum, Integer pageSize) {
        log.info("userId:{}",userId);
        log.info("pageNum:{},pageSize:{}",pageNum,pageSize);
        //1. 设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //2. 查询数据获取分页数据
        List<NursingProject> nursingProjects = nursingProjectMapper.findPage();
        //1. 设置分页参数

        //2. 查询数据获取分页数据
        Page<NursingProject> p=(Page<NursingProject>)nursingProjects;
        //3. 创建分页结果对象
        PageResult<NursingProject> pr = new PageResult<>();
        //4. 设置分页结果对象
        pr.setPage(pageNum);
        pr.setPages(Long.valueOf(p.getPages()));
        pr.setPageSize(pageSize);
        pr.setTotal(p.getTotal());
        pr.setRecords(p.getResult());
        //5. 响应结果对象
        return Result.success(pr);
    }
    @GetMapping("/customer/orders/project/{id}")
    public Result<NursingProject> detail(@PathVariable Integer id) {
        NursingProject npm = nursingProjectMapper.getDetailById(id);
        return Result.success(npm);

    }
}
